package com.controller;

import com.alibaba.fastjson.JSON;
import com.entity.*;
import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class StudentController {

    @Autowired
    private StudentService studentservice;

    @RequestMapping("/abcd")
    public List<Student> getStudent(){
        return studentservice.findAll();
    }

    @RequestMapping("/addStudent")
    public String addStudent(@RequestBody Student student){
        int i=studentservice.addStudent(student);
        return i>0?"success":"error";
    }

    @RequestMapping("/deleteStudent")
    public String deleteStudent(String sno){
        int i=studentservice.deleteStudent(sno);
        return i > 0 ? "error":"success";
    }

    @RequestMapping("/getupdate")
    public String getUpdateStudent(String sno){
      Student student=studentservice.getUpdateStudent(sno);
      String string = JSON.toJSONString(student);
      return string;
    }

    @RequestMapping("/editStudent")
    public String editStudent (@RequestBody Student student){
        int i=studentservice.editStudent(student);
        return i>0?"success":"error";
    }

    @RequestMapping("/showStudent")
    public List<Shows> showStudent(String sno){
        return studentservice.showStudent(sno);
    }

    @RequestMapping("/showArea")
    public List<Area> showArea(){
        return studentservice.showAreaList();
    }

    @RequestMapping("/showAge")
    public List<Age> showAge(){
        return studentservice.showAgeList();
    }

    @RequestMapping("/showPolicy")
    public List<Policy> showSpo(){
        return studentservice.showSpoList();
    }
}
